package com.qiyue.admin.controller.base.dict;

import com.qiyue.admin.biz.base.dict.DictTypeBiz;
import com.qiyue.admin.constant.AdminCommonConstant;
import com.qiyue.admin.entity.base.dict.DictType;
import com.qiyue.admin.vo.DictTree;
import com.qiyue.common.controller.BaseController;
import com.qiyue.common.utils.TreeUtil;
import com.qiyue.utils.ResultUtils;
import com.qiyue.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * created by yebinghuan on 2018/4/2
 */
@RestController
@RequestMapping(AdminCommonConstant.URL.URI_API +"dictType")
@Api(description = "数据字典类型")
public class DictTypeController extends BaseController<DictTypeBiz,DictType>{


    @GetMapping("/tree")
    @ApiOperation("获取数据字典tree")
    public Result<DictTree> getDictTree(){
        List<DictTree> trees  = this.baseBiz.findAll()
                .stream()
                .map(dictType ->{
                        return    new DictTree(dictType.getId(), dictType.getParentId(), dictType.getName(),dictType.getCode());
                }).collect(Collectors.toList());
        return ResultUtils.getResult(  TreeUtil.bulid(trees, (Object) "-1"));
    }
}
